<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="data">...</div>
    <script>
        // 1.创建Ajax对象
        var xhr = new XMLHttpRequest()
        // 2.打开对象的请求链接
        xhr.open('POST', 'http://www.rttop.cn/api/?day=2', true)
        // 设置头的请求类型
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        // 3.发送请求
        xhr.send('name=张三')
        // 4.获取数据
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) { //发送成功
                if (xhr.status == 200) { //接收成功
                    // 输出返回的数据
                    console.log(xhr.responseText)
                    document.getElementById('data').innerHTML = xhr.responseText
                }
            }
        }
    </script>
</body>

</html>